namespace Sckf.MicroService.Services.Catalog.Application.Catalogs;

public partial class CatalogCommandHandler
{
    [EventHandler(Order = 3)]
    public async Task CreateHandleAsync(CreateCatalogCommand command)
    {
        var catalog = new Domain.Entities.Catalog()
        {
            Id = IdGeneratorFactory.SnowflakeGenerator.NewId(),
            Name = command.Name,
            Description = command.Description
        };
        await _catalogRepository.AddAsync(catalog);
        Console.WriteLine("处理方法1");
    }

    [EventHandler(Order = 1)]
    public async Task Create2HandleAsync(CreateCatalogCommand command)
    {
        Console.WriteLine("处理方法2");
    }

    [EventHandler(Order = 2)]
    public async Task Create3HandleAsync(CreateCatalogCommand command)
    {
        Console.WriteLine("处理方法3");
    }

    [EventHandler]
    public async Task UpdateHandleAsync(UpdateCatalogCommand command)
    {
        var catalog = new Domain.Entities.Catalog()
        {
            Id = command.CatalogId,
            Name = command.Name,
            Description = command.Description
        };
        await _catalogRepository.UpdateAsync(catalog);
    }

    [EventHandler]
    public async Task DeleteHandlerAsync(DeleteCatalogCommand command)
        => await _catalogRepository.DeleteAsync(command.CatalogId);
}

public partial class CatalogCommandHandler
{
    private readonly ICatalogRepository _catalogRepository;

    //private readonly IIntegrationEventBus _integrationEventBus;

    private readonly ILogger<CatalogCommandHandler> _logger;

    public CatalogCommandHandler(ICatalogRepository catalogRepository, ILogger<CatalogCommandHandler> logger)
    {
        _catalogRepository = catalogRepository;
        //_integrationEventBus = integrationEventBus;
        _logger = logger;
    }
}
